Skip to content

Allow rdoc-ref to link to non-text files#1376

Merged
st0012 merged 3 commits intoruby:masterfrom
jeremyevans:rdoc-ref-to-non-text-toplevel
Aug 10, 2025
Merged

Allow rdoc-ref to link to non-text files#1376
st0012 merged 3 commits intoruby:masterfrom
jeremyevans:rdoc-ref-to-non-text-toplevel

Conversation

@jeremyevans
Copy link
Copy Markdown
Contributor

It appears the current behavior of disallowing links to non-text files is deliberate, as it was explicitly added in 3628e19. While the commit message explains the change, it doesn't provide a justification for excluding non-text TopLevels. The issue mentioned in the commit message is also unrelated to the change.

It's just as useful to link to a non-text file as it is to link to a text file, so I think it should be allowed. I was surprised when it didn't work. I want to use this feature in tilt's documentation.

If there is a reason to disallow it by default, I think this limitation should be documented. I also I think we should add an option to allow it in that case.

It appears the current behavior of disallowing links to non-text
files is deliberate, as it was explicitly added in
3628e19.  While the commit message
explains the change, it doesn't provide a justification for excluding
non-text TopLevels. The issue mentioned in the commit message is
also unrelated to the change.

It's just as useful to link to a non-text file as it is to link to a
text file, so I think it should be allowed.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jun 12, 2025

Cloudflare Preview Deployment

⚠️ This PR is from a fork, so the preview deployment workflow doesn't run automatically for security reasons.

For Maintainers:

🚀 Click here to run the preview deployment workflow

This will trigger a Cloudflare Pages preview deployment for this PR.

@st0012
Copy link
Copy Markdown
Member

st0012 commented Jun 21, 2025

I agree with the goal but I think we need a bit more changes to achieve that.

To test the PR, I added {Link}[rdoc-ref:lib/rdoc/cross_reference.rb] to readme.rdoc. But clicking it doesn't bring me to the right page. The reason seems to be because cross_reference.rb's uri path is /RDoc/CrossReference.html but it's not successfully generated in the html link.
And can you add some test cases to test/rdoc/rdoc_markup_to_html_crossref_test.rb as well? Thanks

@jeremyevans
Copy link
Copy Markdown
Contributor Author

I agree with the goal but I think we need a bit more changes to achieve that.

To test the PR, I added {Link}[rdoc-ref:lib/rdoc/cross_reference.rb] to readme.rdoc. But clicking it doesn't bring me to the right page. The reason seems to be because cross_reference.rb's uri path is /RDoc/CrossReference.html but it's not successfully generated in the html link.

The link is correct, the issue is that darkfish doesn't generate the page. Added a commit to fix darkfish, and updated the darkfish tests to test that it is generated. When I was testing earlier versions of this, I was using hanna (as I do for all my projects), which has always generated doc files for non-text files.

And can you add some test cases to test/rdoc/rdoc_markup_to_html_crossref_test.rb as well? Thanks

The first commit already tests resolution of non-text files:

  assert_ref @top_level, 'xref_data.rb'

Can you let me know which additional tests you would like?

@jeremyevans jeremyevans requested a review from st0012 August 1, 2025 19:03
Copy link
Copy Markdown
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I think I understand the issue here better now:

  • Themes can decide whether they want to display non-text files. hanna displays them but darkfish doesn't
  • But RDoc's cross referencing feature doesn't allow referencing to non-text files (e.g. lib/foo.rb) regardless if the theme generates them or not

Is my understanding correct?
If it is:

  • I think it's better to revert the 2nd commit as it makes darkfish generate a lot of new pages while most of them are empty. Sorry for the back and forth.
  • Can you also update rdoc-ref's documentation in doc/rdoc/markup_reference.rb to mention how to link to files?


def page(name)
@text_files_hash.each_value.find do |file|
@files_hash.each_value.find do |file|
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the comment too?

@jeremyevans jeremyevans force-pushed the rdoc-ref-to-non-text-toplevel branch from d42c1f5 to 45c45d7 Compare August 6, 2025 23:02
@jeremyevans jeremyevans temporarily deployed to fork-preview-protection August 6, 2025 23:02 — with GitHub Actions Inactive
@jeremyevans
Copy link
Copy Markdown
Contributor Author

I removed the darkfish commit, and added commits to updated the comment and show a usage example. Probably best to squash merge these, but I kept them separate to facilitate review.

@matzbot
Copy link
Copy Markdown
Collaborator

matzbot commented Aug 7, 2025

🚀 Preview deployment available at: https://5d13ea09.rdoc-6cd.pages.dev (commit: 45c45d7)

Copy link
Copy Markdown
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@st0012 st0012 merged commit 6639fe1 into ruby:master Aug 10, 2025
33 checks passed
st0012 added a commit that referenced this pull request Mar 14, 2026
RDoc's cross-reference system auto-links filenames like `array.c`
when encountered in documentation text. However, non-text source
files are not meant to have their own documentation pages, so these
auto-generated links are always broken.

Only suppress auto-linking. Explicit `rdoc-ref:` links to non-text
files (enabled by #1376) continue to work.
st0012 added a commit that referenced this pull request Mar 14, 2026
RDoc's cross-reference system auto-links filenames like `array.c`
when encountered in documentation text. However, non-text source
files are not meant to have their own documentation pages, so these
auto-generated links are always broken.

Only suppress auto-linking. Explicit `rdoc-ref:` links to non-text
files (enabled by #1376) continue to work.
tompng pushed a commit that referenced this pull request Mar 21, 2026
## Summary
- RDoc's cross-reference system auto-links filenames like `array.c` when
encountered in documentation text, but non-text source files are not
meant to have their own documentation pages, so these links are always
broken (e.g.
https://docs.ruby-lang.org/en/master/extension_rdoc.html#class-library)
- Only suppress auto-linking in `ToHtmlCrossref#link`. Explicit
`rdoc-ref:` links to non-text files (enabled by #1376) continue to work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants